package com.tools.app.manager;

import com.tools.app.AppApplication;
import com.tools.app.cache.SmartMonitorCache;
import com.tools.app.sdk.GoogleAnalyticsImpl;
import com.tools.app.service.impl.AppHttpService;
import com.tools.app.service.impl.AppLocalService;
import com.tools.app.service.impl.AppProtocolFactory;
import com.tools.app.store.AppConfig;
import com.tools.app.store.AppSharedPrefManager;
import com.tools.app.task.AppServiceWrapper;
import com.tools.app.task.AppTaskMarkPool;
import com.tools.cleanmaster.manager.CleanBeanManager;

/**
 * Created by ChenLi on 2017/12/13.
 */

public class AppBeanManager extends CleanBeanManager {

    private AppApplication mAppApplication;

    public AppBeanManager(AppApplication imContext) {
        super(imContext);
        mAppApplication = (AppApplication) imContext;
    }

    @Override
    protected <T> T createBean(Class<T> clazz, String mark) {
        Object obj = null;
        if (clazz == AppSharedPrefManager.class) {
            obj = new AppSharedPrefManager(mAppApplication);

        } else if (clazz == AppTaskMarkPool.class) {
            obj = new AppTaskMarkPool();

        } else if (clazz == AppConfig.class) {
            obj = new AppConfig();

        } else if (clazz == AppServiceWrapper.class) {
            obj = new AppServiceWrapper(imContext, getAppLocalService());

        } else if (clazz == AppLocalService.class) {
            obj = new AppLocalService(getAppHttpService(), imContext);

        } else if (clazz == AppHttpService.class) {
            obj = new AppHttpService(imContext, new AppProtocolFactory());

        } else if (clazz == AppManager.class) {
            obj = new AppManager((AppApplication) imContext);

        } else if (clazz == GoogleAnalyticsImpl.class) {
            obj = new GoogleAnalyticsImpl((AppApplication) imContext);

        } else if (clazz == SmartMonitorCache.class) {
            obj = new SmartMonitorCache((AppApplication) imContext);

        } else {
            //必须调用 super.createBean(clazz, mark) 以完成 底层组件的创建
            obj = super.createBean(clazz, mark);
        }
        return (T) obj;

    }

    /**
     * cooler SharedPref 管理器
     *
     * @return
     */
    public AppSharedPrefManager getAppSharedPrefManager() {
        return getBean(AppSharedPrefManager.class);
    }

    /**
     * 任务池
     *
     * @return
     */
    public AppTaskMarkPool getAppTaskMarkPool() {
        return getBean(AppTaskMarkPool.class);
    }

    /**
     * 任务池
     *
     * @return
     */
    public AppServiceWrapper getAppServiceWrapper() {
        return getBean(AppServiceWrapper.class);
    }

    /**
     * 获取广告配置缓存
     *
     * @return
     */
    public AppConfig getAppConfig() {
        return getBean(AppConfig.class);
    }

    /**
     * 本地服务
     *
     * @return
     */
    public AppLocalService getAppLocalService() {
        return getBean(AppLocalService.class);
    }

    /**
     * 网络请求服务
     *
     * @return
     */
    public AppHttpService getAppHttpService() {
        return getBean(AppHttpService.class);
    }

    /**
     * cooler manager
     *
     * @return
     */
    public AppManager getAppManager() {
        return getBean(AppManager.class);
    }

    /**
     * GA manager
     *
     * @return
     */
    public GoogleAnalyticsImpl getGoogleAnalytics() {
        return getBean(GoogleAnalyticsImpl.class);
    }

    /**
     * monitor cache
     *
     * @return
     */
    public SmartMonitorCache getSmartMonitorCache() {
        return getBean(SmartMonitorCache.class);
    }

}
